package com.stn.zjx.givingtreasure.activity.subldle;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.OrientationHelper;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.lcodecore.tkrefreshlayout.RefreshListenerAdapter;
import com.lcodecore.tkrefreshlayout.TwinklingRefreshLayout;
import com.lcodecore.tkrefreshlayout.header.progresslayout.ProgressLayout;
import com.stn.zjx.givingtreasure.R;
import com.stn.zjx.givingtreasure.adapter.AddressManagerItemListAdapter;
import com.stn.zjx.givingtreasure.adapter.IdleSongItemListAdapter;
import com.stn.zjx.givingtreasure.base.BaseActivity;
import com.stn.zjx.givingtreasure.event.NetWorkEvent;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class SubIdleActivity extends BaseActivity {
    @BindView(R.id.back_bt)
    RelativeLayout backBt;
    @BindView(R.id.robot_open_bt)
    RelativeLayout robotOpenBt;
    @BindView(R.id.clear_search_content_bt)
    RelativeLayout clearSearchContentBt;
    @BindView(R.id.search_store_edit)
    EditText searchStoreEdit;
    @BindView(R.id.search_edit_bg)
    LinearLayout searchEditBg;
    @BindView(R.id.search_store_bg)
    RelativeLayout searchStoreBg;
    @BindView(R.id.search_tv_bt)
    TextView searchTvBt;
    @BindView(R.id.head)
    LinearLayout head;
    @BindView(R.id.rv)
    RecyclerView rv;
    @BindView(R.id.twinkling_refresh)
    TwinklingRefreshLayout twinklingRefresh;
    @BindView(R.id.no_data_tv)
    TextView noDataTv;
    private boolean isMoreLoading = false;
    private int visibleItemCount = 0;
    private LinearLayoutManager lm;
    private IdleSongItemListAdapter adapter;
    private int pageNow=1;

    @Override
    public void networkStatus(NetWorkEvent netWorkEvent) {

    }

    @Override
    public void initComponent() {
        searchStoreEdit.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) {
                if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                    if (TextUtils.isEmpty(searchStoreEdit.getText().toString().trim())) {
                        showToast(getString(R.string.search_content_is_not_null));
                        return false;
                    }

                    return true;
                }
                return false;
            }
        });
        rv.setLayoutManager(lm = new LinearLayoutManager(this, OrientationHelper.VERTICAL, false));
        rv.setAdapter(adapter = new IdleSongItemListAdapter(this));
        ProgressLayout headerView = new ProgressLayout(this);
        headerView.setColorSchemeResources(R.color.colorAccent);
        twinklingRefresh.setHeaderView(headerView);
        twinklingRefresh.setOnRefreshListener(new RefreshListenerAdapter() {
            @Override
            public void onRefresh(final TwinklingRefreshLayout refreshLayout) {
             //   initRefresh();
            }

            @Override
            public void onLoadMore(final TwinklingRefreshLayout refreshLayout) {

            }
        });

        rv.setOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                super.onScrollStateChanged(recyclerView, newState);
                if (isMoreLoading == false && newState == RecyclerView.SCROLL_STATE_IDLE && visibleItemCount == adapter.dataBeanList.size() - 1 &&
                        adapter.dataBeanList.size() >= pageNow * 10) {
                  //  initAppend();
                }
            }

            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);
                visibleItemCount = lm.findLastVisibleItemPosition();
            }
        });
   //     twinklingRefresh.startRefresh();
       List<String> ar=new ArrayList<>();
        ar.add("hjjjj");
        adapter.refreshList(ar);
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_substitution);
        ButterKnife.bind(this);
        initComponent();
    }

    @OnClick({R.id.back_bt})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.back_bt:
                finish();
                break;
        }
    }
}
